package cam.School.Services;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import cam.School.DataAccessObject.DAOFactory;
import cam.School.DataAccessObject.SubjectDAO;
import cam.School.DataTransfertObject.SubjectDTO;

@Path("/subjectService")
public class SubjectService {
	
	@GET
	@Path("/getAllSubjects")
	@Produces(MediaType.APPLICATION_JSON)
	public Response getAllSubjects() {
		DAOFactory javabase = DAOFactory.getInstance("javabase.jdbc");
		SubjectDAO SubjectDAO = javabase.getSubjectDAO();	
		  
		return Response.ok(SubjectDAO.getAllSubject()).build();	
	}
	
	@GET
	@Path("/getAllSubjectName")
	@Produces(MediaType.APPLICATION_JSON)
	public Response getAllSubjectName() {
		DAOFactory javabase = DAOFactory.getInstance("javabase.jdbc");
		SubjectDAO SubjectDAO = javabase.getSubjectDAO();	
		  
		return Response.ok(SubjectDAO.getAllSubjectName()).build();	
	}
	
	@GET
	@Path("/getSubjectById/{SubjectId}")
	@Produces(MediaType.APPLICATION_JSON)
	public Response getSubjectById(@PathParam("SubjectId") int studentId ) {		
		return null;		
	}
	
	@GET
	@Path("/getSubjectByName/{SubjectName}")
	@Produces(MediaType.APPLICATION_JSON)
	public SubjectDTO getSubjectByName(@PathParam("SubjectName") String studentName ) {		
		return null;		
	}
	
	
	@GET
	@Path("/getSubjectByClassCategory/{categoryName}")
	@Produces(MediaType.APPLICATION_JSON)
	public SubjectDTO getSubjectByClassCategory(@PathParam("categoryName") String categoryName ) {		
		return null;		
	}
	
	
	@GET
	@Path("/getSubjectByBirthdayAndName?name={studentName}&birthday={studentBirthday}")
	@Produces(MediaType.APPLICATION_JSON)
	public SubjectDTO getSubjectByBirthdayAndName(@PathParam("studentName") String studentName ) {		
		return null;		
	}
	
	@GET
	@Path("/getSubjectByMaticulNumber/{studentMatricul}")
	@Produces(MediaType.APPLICATION_JSON)
	public SubjectDTO getSubjectByMaticulNumber(@PathParam("studentMatricul") String studentMatricul ) {		
		return null;		
	}	
		
	@POST
	@Path("/insertSubject/{SubjectData}")
	@Produces(MediaType.TEXT_XML)
	public boolean insertSubject(@PathParam("studentMatricul") String SubjectData ) {				  
		
//		SubjectData ={
//				  "FirstName":"NewFirstName",
//				  "LastName":"NewLastName",
//				  "StreetNr":"NewStreetNr",
//				  "City":"NewCity",
//				  "ZipCode":"90567",
//				  "Country":"NewCountry",
//				  "Birthday":"10.10.1984",
//				  "Email":"newEmail@yahoo.de",
//				  "CellPhone":"00237998764526",
//				  "WorkPhone":"0023733457635",
//				  "IsPrincipalTeacher":"true",
//				  "Deleted:"false",
//				  "FirstRegistration:"10.11.2014",
//				  "LastUpdate:"10.11.2014",
//				  "MatriculationNumber:"NewMatriculationNumber",
//				  "PictureId":"234",
//				  "Profession:"English Teacher"
//		}
		return true; // or false falls es nicht gespeichert werden kann.		
	}
	
	@POST
	@Path("/updateSubject/{SubjectData}")
	@Produces(MediaType.TEXT_XML)
	public boolean updateSubject(@PathParam("studentMatricul") String SubjectData ) {				  
		//search by studentMatricul
//		SubjectData ={
//				  "FirstName":"NewFirstName",
//				  "LastName":"NewLastName",
//				  "StreetNr":"NewStreetNr",
//				  "City":"NewCity",
//				  "ZipCode":"90567",
//				  "Country":"NewCountry",
//				  "Birthday":"10.10.1984",
//				  "Email":"newEmail@yahoo.de",
//				  "CellPhone":"00237998764526",
//				  "WorkPhone":"0023733457635",
//				  "IsPrincipalTeacher":"true",
//				  "Deleted:"false",
//				  "FirstRegistration:"10.11.2014",
//				  "LastUpdate:"10.11.2014",
//				  "MatriculationNumber:"NewMatriculationNumber",
//				  "PictureId":"234",
//				  "Profession:"English Teacher"
//		}
		return true; // or false falls es nicht gespeichert werden kann.		
	}
	
	@POST
	@Path("/deleteSubject/{studentMatricul}")
	@Produces(MediaType.TEXT_XML)
	public boolean deleteSubject(@PathParam("studentMatricul") String studentMatricul ) {				  
		
		return true; // or false falls es nicht gespeichert werden kann.		
	}	
	
	@POST
	@Path("/deleteSubject?id={studentMatricul}&state={state}")
	@Produces(MediaType.TEXT_XML)
	public boolean changeStateSubject(@PathParam("studentMatricul") String studentMatricul ) {				  
		//TODO 
		return true; // or false falls es nicht gespeichert werden kann.		
	}
	
	
	@POST
	@Path("/getSubjectWeeklyPlan?id={studentMatricul}")
	@Produces(MediaType.TEXT_XML)
	public String getSubjectWeeklyPlan(@PathParam("studentMatricul") String studentMatricul ) {				  
		//TODO 
		return "TO DO"; 		
	}

}
